package com.codeavatar.hardwaretester.adapter;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.codeavatar.catools.adapter.CaRecyclerViewAdapter;
import com.codeavatar.catools.helper.CaLogHelper;
import com.codeavatar.hardwaretester.R;
import com.codeavatar.hardwaretester.activity.hardware.bluetooth.ServerActivity;
import com.codeavatar.hardwaretester.model.MenuModel;
import com.codeavatar.hardwaretester.model.MenuModel;

import java.util.ArrayList;
import java.util.List;

/**
 * +----------------------------------------------------------------------
 * | @Author: codeavatar   @Year：2022
 * +----------------------------------------------------------------------
 * | @Email: codeavatar@aliyun.com
 * +----------------------------------------------------------------------
 **/
public class RvwMenuListAdapter extends CaRecyclerViewAdapter {

    private final String TAG = this.getClass().getSimpleName();

    private Context context;
    private List<MenuModel> dataList = new ArrayList<>();
    private IClickCallback clickCallback;

    public RvwMenuListAdapter(@NonNull Context context,IClickCallback clickCallback){
        this.context = context;
        this.clickCallback = clickCallback;
    }

    //++++++++++++++++++++++++++++++++++++++
    //++ 外部方法
    //++++++++++++++++++++++++++++++++++++++

    public void setDataList(List<MenuModel> list){
        if(null != list && list.size() > 0){
            this.dataList.clear();
            this.dataList.addAll(list);
        }
    }

    public void appendDataList(List<MenuModel> list){
        if(null != list && list.size() > 0){
            this.dataList.addAll(list);
        }
    }

    //单周事件回调
    public interface IClickCallback{
        void onClick(MenuModel menu,int position);
        void onChildClick(View v,int position);
    }

    //++++++++++++++++++++++++++++++++++++++
    //++ 重写方法
    //++++++++++++++++++++++++++++++++++++++

    @Override
    public void bindView(RvViewHolder holder, int position) {
        MenuModel mm = dataList.get(position);
        holder.setTextView(R.id.tvw_option,mm.getTitle());
    }

    @Override
    public void bindClick(View v, int position) {
        MenuModel mm = dataList.get(position);
        clickCallback.onClick(mm,position);
    }

    @Override
    public void bindChildClick(View v, int position) {
        clickCallback.onChildClick(v,position);
//        Bundle extras = new Bundle();
//        switch (v.getId()){
//            default:
//                CaLogHelper.warn(TAG, context.getResources().getString(R.string.ca_txt_no_resid));
//                break;
//        }
    }

    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public int getResId() {
        return R.layout.layout_menu_list_item;
    }

    @Override
    public Context getContext() {
        return null;
    }

    @Override
    public boolean getClickable() {
        return true;
    }
}
